import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

/**
 * @Author: 祺诺
 * @Name; xqf
 * @Date: 2020/12/24 20:05
 */
@WebServlet("/text2")
public class text2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        Cookie cookie = new Cookie("JSESSIONID", session.getId());
        //指定cookie的作用范围
        cookie.setPath(req.getContextPath());
        //设置持久化cookie
        cookie.setMaxAge(1000);
        //设置Http可用
        cookie.setHttpOnly(true);
        resp.addCookie(cookie);
        session.setAttribute("username","张三");
        resp.sendRedirect("/text3");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
